home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pavt150.zip / CAPI.ZIP / JAMHINFO.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  2KB  |  85 lines

  1. /*
  2. **  JAM(mbp) - The Joaquim-Andrew-Mats Message Base Proposal
  3. **
  4. **  C API
  5. **
  6. **  Written by Joaquim Homrighausen.
  7. **
  8. **  ----------------------------------------------------------------------
  9. **
  10. **  jamhinfo.c (JAMmb)
  11. **
  12. **  Updating of header info block at beginning of header file
  13. **
  14. **  Copyright 1993 Joaquim Homrighausen, Andrew Milner, Mats Birch, and
  15. **  Mats Wallin. ALL RIGHTS RESERVED.
  16. **
  17. **  93-06-28    JoHo
  18. **  Initial coding.
  19. */
  20. #define JAMCAPI 1
  21.  
  22. #include "jammb.h"
  23.  
  24. /*
  25. **  Update or retrieve header info block at beginning of header file. Returns
  26. **  1 upon success and 0 upon failure.
  27. */
  28. int _JAMPROC JAMmbUpdateHeaderInfo(JAMAPIRECptr apirec, int WriteIt)
  29. {
  30.     /* Make sure it's open */
  31.     if (!apirec->isOpen)
  32.         {
  33.         apirec->APImsg=JAMAPIMSG_ISNOTOPEN;
  34.         return (0);
  35.         }
  36.  
  37.     /* Make sure we have lock if we need to */
  38.     if (WriteIt && !apirec->HaveLock)
  39.         {
  40.         apirec->APImsg=JAMAPIMSG_ISNOTLOCKED;
  41.         return (0);
  42.         }
  43.  
  44.     /* Seek to beginning of file */
  45.     if (apirec->SeekFunc(apirec, apirec->HdrHandle, JAMSEEK_SET, 0L)!=0L)
  46.         {
  47.         apirec->APImsg=JAMAPIMSG_SEEKERROR;
  48.         return (0);
  49.         }
  50.  
  51.     /* Update ModCounter if told to*/
  52.     if (WriteIt)
  53.         {
  54.         apirec->HdrInfo.ModCounter++;
  55.  
  56.         if (apirec->HdrInfo.BaseMsgNum==0L)
  57.             apirec->HdrInfo.BaseMsgNum=1L;
  58.  
  59.         /* Update header info record */
  60.         if (apirec->WriteFunc(apirec, apirec->HdrHandle, &apirec->HdrInfo, (INT32)sizeof(JAMHDRINFO))!=(INT32)sizeof(JAMHDRINFO))
  61.             {
  62.             apirec->HdrInfo.ModCounter--;
  63.             apirec->APImsg=JAMAPIMSG_CANTWRFILE;
  64.             return (0);
  65.             }
  66.         }
  67.     else
  68.         /* Fetch header info record */
  69.         {
  70.         if (apirec->ReadFunc(apirec, apirec->HdrHandle, &apirec->HdrInfo, (INT32)sizeof(JAMHDRINFO))!=(INT32)sizeof(JAMHDRINFO))
  71.             {
  72.             apirec->APImsg=JAMAPIMSG_CANTRDFILE;
  73.             return (0);
  74.             }
  75.  
  76.         if (apirec->HdrInfo.BaseMsgNum==0L)
  77.             apirec->HdrInfo.BaseMsgNum=1L;
  78.         }
  79.  
  80.     apirec->APImsg=JAMAPIMSG_NOTHING;
  81.     return (1);
  82. }
  83.  
  84. /* end of file "jamhinfo.c" */
  85.